package com.bo.service.impl;

import com.bo.mapper.DeptMapper;
import com.bo.pojo.Dept;
import com.bo.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author huangbo
 * @version 1.0.0
 */
@Service
public class DeptServiceImpl implements DeptService {   //实现接口的方法，记得使用implements继承

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }

    @Override
    public void delete(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());    //补充属性
        deptMapper.add(dept);
    }

    @Override
    public Dept find(Integer id) {
        return deptMapper.find(id);
    }

    @Override
    public void change(Dept dept) {
        Dept newDept = deptMapper.find(dept.getId());
        newDept.setName(dept.getName());
        newDept.setUpdateTime(LocalDateTime.now()); //记得更新修改时间，而不是仅仅修改name
        deptMapper.change(newDept);
    }
}
